import { createApp } from 'vue'
import App from './App.vue'
// 引入pinia
import { createPinia } from 'pinia'
// 引入持久化存存储
import piniapluginPersistedstate from "pinia-plugin-persistedstate"
// 引入路由
import router from './router/index'
// 引入element-plus
import ElementPlus from 'element-plus';
// 引入存储菜单的store
import useMenuList from "@/store/menulist.js"
import 'element-plus/dist/index.css';
// 引入nprogress加载条的样式
import 'nprogress/nprogress.css'
// 引入公共样式
import "@/assets/styles/common.css"

let aPP = createApp(App)
let pinia = createPinia()
// 持久化存储
pinia.use(piniapluginPersistedstate)

// 路由前置守卫钩子
router.beforeEach(async (to, from) => {
    // 获取token
    let token = sessionStorage.getItem('tk')
    // 如果没有token
    if (!token) {
        if (to.path !== '/login') {
            return {
                path: '/login'
            }
        }
    } else {
        // 如果有token就发起请求获取菜单数据
        let menuStore = useMenuList()
        // 判断菜单数据不为空就发起请求
        // if(menuStore.menulist.length>0){
            menuStore.getMenuList()
        // }
    }
})





aPP.use(router)

aPP.use(ElementPlus)

aPP.use(pinia)

aPP.mount('#app')

